package com.sluggard.ai.config;

import com.sluggard.ai.tools.SystemTools;
import org.springframework.ai.chat.client.ChatClient;
import org.springframework.ai.chat.client.advisor.MessageChatMemoryAdvisor;
import org.springframework.ai.chat.client.advisor.SimpleLoggerAdvisor;
import org.springframework.ai.chat.memory.MessageWindowChatMemory;
import org.springframework.ai.chat.memory.repository.jdbc.JdbcChatMemoryRepository;
import org.springframework.ai.chat.model.ChatModel;
import org.springframework.ai.tool.method.MethodToolCallbackProvider;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 类描述：
 *
 * @author lizheng
 * @created 2025/4/22 17:35
 */
@Configuration
public class ChatClientConfig {

    @Autowired
    JdbcChatMemoryRepository chatMemoryRepository;

    @Bean
    public ChatClient chatClient(ChatModel chatModel, SystemTools systemTools) {
        return ChatClient.builder(chatModel)
                .defaultToolCallbacks(MethodToolCallbackProvider.builder()
                        .toolObjects(systemTools)
                        .build())
                .defaultAdvisors(
                        MessageChatMemoryAdvisor.builder(MessageWindowChatMemory.builder()
                                .chatMemoryRepository(chatMemoryRepository)
                                .maxMessages(10)
                                .build()).build(),
                        new SimpleLoggerAdvisor()
                )
                .build();
    }


}
